"""
Django settings for it_assistant project.
"""

import os
import sys
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# 添加apps目录到Python路径
sys.path.insert(0, os.path.join(BASE_DIR, 'apps'))

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-49e8)#hf^1rmzbhrrkzm^bvb%sdwhot5-qjln1k@u@xk2nqf%c'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ["*"]

# Application definition
INSTALLED_APPS = [
    'simpleui',  # 必须在admin之前
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    
    # 第三方应用
    'import_export',
    'django_cryptography',
    
    # 自定义应用
    'assets',
    'deepseek', 
    'knowledge',
    'network',
    'credentials',
    'security',
    'dashboard',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'it_assistant.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / 'templates'],  # 添加模板目录
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'it_assistant.wsgi.application'

# Database
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}

# Password validation
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
LANGUAGE_CODE = 'zh-hans'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Static files
STATIC_URL = '/static/'
STATICFILES_DIRS = [
    BASE_DIR / 'static',
]

# Media files
MEDIA_URL = '/media/'
MEDIA_ROOT = BASE_DIR / 'media'

# Default primary key field type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# DeepSeek配置
DEEPSEEK_CONFIG = {
    'api_key': 'sk-8e75d919eed64e4091aeffa024c681b3',  # 您的API密钥
    'base_url': 'https://api.deepseek.com',
    'model': 'deepseek-chat',
}
# 百度配置 bce-v3/ALTAK-AeJVG7K8c21vEjJWn3SmY/3e518486ea4d34f7753d5f0e2535f8b57e4a77f2

# 智谱服务助手 276f10e389194d69977d79f611eec5ce.1dh5VmbbKHE4tyTq


# SimpleUI配置
SIMPLEUI_CONFIG = {
    'system_keep': False,
    'menu_display': ['资产管理', '网络资源', '凭据管理', '安全中心', '知识库', 'DeepSeek AI', '权限认证'],
    'dynamic': True,
    'menus': [
        {
            'name': '资产管理',
            'icon': 'fas fa-server',
            'models': [
                {
                    'name': '业务系统',
                    'icon': 'fas fa-desktop',
                    'url': 'admin/assets/businesssystem/'
                },
                {
                    'name': '服务器',
                    'icon': 'fas fa-hdd',
                    'url': 'admin/assets/server/'
                }
            ]
        },
        {
            'name': '网络资源',
            'icon': 'fas fa-network-wired',
            'models': [
                {
                    'name': 'IP地址段',
                    'icon': 'fas fa-map-marker-alt',
                    'url': 'admin/network/networksegment/'
                },
                {
                    'name': '公网IP',
                    'icon': 'fas fa-globe',
                    'url': 'admin/network/publicip/'
                }
            ]
        },
        {
            'name': '凭据管理',
            'icon': 'fas fa-key',
            'models': [
                {
                    'name': '账号密码',
                    'icon': 'fas fa-user-lock',
                    'url': 'admin/credentials/credential/'
                }
            ]
        },
        {
            'name': '安全中心',
            'icon': 'fas fa-shield-alt',
            'models': [
                {
                    'name': '安全评估',
                    'icon': 'fas fa-chart-bar',
                    'url': 'admin/security/securityassessment/'
                },
                {
                    'name': '安全项目',
                    'icon': 'fas fa-tasks',
                    'url': 'admin/security/securityproject/'
                }
            ]
        },
        {
            'name': '知识库',
            'icon': 'fas fa-book',
            'models': [
                {
                    'name': '文档管理',
                    'icon': 'fas fa-file',
                    'url': 'admin/knowledge/document/'
                }
            ]
        },
        {
            'name': 'DeepSeek AI',
            'icon': 'fas fa-robot',
            'url': '/deepseek/chat/',
            'newTab': True  # 在新标签页打开
        },
        {
            'name': '仪表盘',
            'icon': 'fas fa-tachometer-alt',
            'url': '/dashboard/',
            'newTab': True
        }
    ]
}

SIMPLEUI_HOME_INFO = False
SIMPLEUI_ANALYSIS = False
SIMPLEUI_DEFAULT_THEME = 'admin.lte.css'

# 图标配置
SIMPLEUI_ICON = {
    '资产管理': 'fas fa-server',
    '网络资源': 'fas fa-network-wired', 
    '凭据管理': 'fas fa-key',
    '安全中心': 'fas fa-shield-alt',
    '知识库': 'fas fa-book',
    'DeepSeek AI': 'fas fa-robot',
    '仪表盘': 'fas fa-tachometer-alt',
    '权限认证': 'fas fa-users',
}

# 日志配置
LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'level': 'INFO',
            'class': 'logging.FileHandler',
            'filename': BASE_DIR / 'debug.log',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'INFO',
            'propagate': True,
        },
    },
}

# 安全配置（开发环境可暂时关闭）
CSRF_TRUSTED_ORIGINS = ['http://localhost:8000', 'http://127.0.0.1:8000']

# SimpleUI 完整配置
SIMPLEUI_HOME_INFO = False
SIMPLEUI_ANALYSIS = False
SIMPLEUI_LOADING = False
SIMPLEUI_DEFAULT_THEME = 'admin.lte.css'

# 首页配置
SIMPLEUI_HOME_PAGE = '/dashboard/'
SIMPLEUI_HOME_TITLE = '仪表盘'
SIMPLEUI_HOME_ICON = 'fas fa-tachometer-alt'

# 菜单配置
SIMPLEUI_CONFIG = {
    'system_keep': False,
    'menu_display': ['资产管理', '网络资源', '凭据管理', '安全中心', '知识库', 'DeepSeek AI', '仪表盘', '权限认证'],
    'dynamic': True,
    'menus': [
        {
            'app': 'assets',
            'name': '资产管理',
            'icon': 'fas fa-server',
        },
        {
            'app': 'network', 
            'name': '网络资源',
            'icon': 'fas fa-network-wired',
        },
        {
            'app': 'credentials',
            'name': '凭据管理', 
            'icon': 'fas fa-key',
            'models': [
                {
                    'name': '账号密码',
                    'icon': 'fas fa-user-lock',
                    'url': 'credentials/credential/'
                },
                {
                    'name': '分类管理', 
                    'icon': 'fas fa-folder',
                    'url': 'credentials/credentialcategory/'
                },
                {
                    'name': '导入日志',
                    'icon': 'fas fa-history',
                    'url': 'credentials/credentialimportlog/'
                }
            ]
        },
        {
            'app': 'security',
            'name': '安全中心',
            'icon': 'fas fa-shield-alt',
        },
        {
            'app': 'knowledge',
            'name': '知识库',
            'icon': 'fas fa-book',
        },
        {
            'name': 'DeepSeek AI',
            'icon': 'fas fa-robot', 
            'url': '/deepseek/chat/',
        },
        {
            'name': '仪表盘',
            'icon': 'fas fa-tachometer-alt',
            'url': '/dashboard/',
        },
        {
            'app': 'auth',
            'name': '权限认证',
            'icon': 'fas fa-users',
            'models': [
                {
                    'name': '用户',
                    'icon': 'fas fa-user',
                    'url': 'auth/user/'
                },
                {
                    'name': '用户组',
                    'icon': 'fas fa-users',
                    'url': 'auth/group/'
                }
            ]
        }
    ]
}

# 图标配置
SIMPLEUI_ICON = {
    '资产管理': 'fas fa-server',
    '网络资源': 'fas fa-network-wired',
    '凭据管理': 'fas fa-key', 
    '安全中心': 'fas fa-shield-alt',
    '知识库': 'fas fa-book',
    'DeepSeek AI': 'fas fa-robot',
    '仪表盘': 'fas fa-tachometer-alt',
    '权限认证': 'fas fa-users',
}